/**
	1 在役管段  查询内检测环焊缝，弯头数据
    0 非在役管段 查询基础环焊缝，冷弯头，煨弯头
 */
var enlist=1;
/**
 * 页面初始化执行js
 */
$(function(){


	$('html,body').css({"overflow":"visible"});


	$("div.jance-baogao").live("click",function(){
		var taskIdVal=window.task.val();
		var param=[];
		var lineName=window.line.val('text');
		var taskName=window.task.val('text');
		param.push({name:"businessId",value:taskIdVal});
		param.push({name:"downFileName",value:lineName+taskName+"检测报告"});

		if(checkForm([window.line,window.task]) && checkFormVerify($("#JQ_form")))
		{
			downFile(path+"/comm/downZipFiles.json",param)
		}

	});

	$(".selectLine a").click(function(){

		//查询检测任务
		resultAjax(path+"/comm/taskByLineId.json","lineId="+$(this).find("a").attr("id"),parseTask,"JSON");

	});



	$(".exportExlBtn").click(function(){
		$('.zy-i-input').css({border:"none"});
		$('.zy-i-input').css({height:"35px"});
		var lineName=window.line.val('text');
		var taskName=window.task.val('text');
		var name = lineName+taskName+$(this).attr("exportName");
		if(window.total == 0)
		{
			$(this).MSG({
				content: '没有需要导出的记录'
			});
		}else {
			resultAjax(path+"/comm/checkOutTime.json","",function(data,param){
				var exportFile = $(this).EXPT({
					name:param ,
					yesBtnAct: function(callback){
						exportExl(exportFile.name);
						callback();
					}
				});
			},"json",name);


		}





	});

	$(".searchBtn").unbind("click").click(function(){
		var pageSize=$("div.body_data .paging-footer .down-list .total").text();
		submitForm(1,parseInt(pageSize));
		if($('#JQ_toggle_map_span').hasClass("active")){
			var taskId=window.task.val();
			$("#frameId").attr("src",$("#frameId").attr("gisSrc") + "/baseMapInspDefect.jsp?taskId="+taskId);

		}
	});

    //$("#JQ_toggle_map_span").on("click",function(){
    //
	//});
	$("#JQ_toggle_list_span").on("click",function(){
		$("#JQ_export_btn_01").css({display:""});
		$("#JQ_delete_01").css({display:""})
	});

	//去评价
	$(".toApprarse").unbind("click").click(function(){
		$('.zy-i-input').css({border:"none"});
		$('.zy-i-input').css({height:"35px"});
		var lineName=window.line.val('text');
		var taskName=window.task.val('text');
		var name = lineName+taskName+$(this).attr("exportName");
		resultAjax(path+"/comm/checkOutTime.json","",function(data,param){
			var exportFile = $(this).EXPT({
				title:'评价',
				name:name ,
				yesBtnAct: function(callback){
					exportApprarse(exportFile.name);
					callback();
				}
			});
		},"json",name);


	});

	/**
	 * gis查看
	 */





		$(".zy-toggle-label span").each(function(i){
			$(this).on('click',function(){
				var obj = [window.line,window.task];


				if(checkForm(obj) &&　checkFormVerify($("#JQ_form"))) {
					$(this).addClass('active');
					$(this).siblings().removeClass('active');
					$('.lsk-map .lsk-left').eq(i).removeClass('none');
					$('.lsk-map .lsk-left').eq(i).siblings().addClass('none')
				}
			})
		});
		$("span[btn='gis']").click(function(){
			var taskId=window.task.val();
			var obj = [window.line,window.task];


			if(checkForm(obj) &&　checkFormVerify($("#JQ_form")))
			{
				$("#frameId").attr("src",$("#frameId").attr("gisSrc") + "/baseMapInspDefect.jsp?taskId="+taskId);

				//$('.l-r .right').animate({'width':'98%'},'slow','easeInCirc',function(){
				//    $('.gis-list').removeClass('none')
				//    $('.right .paging-footer').removeClass('none')
				//})

				$('.l-r .right').css({borderColor:'#2f80be'});
				$('.l-r .right').find('iframe').css({'visibility':'visible'});
				$('.l-r .right').find('iframe').attr({'width':'100%'});

				$('.se-bt').addClass('none');
				$('.se-bt1').addClass('none')
				$("#JQ_export_btn_01").css({display:"none"});
				$("#JQ_delete_01").css({display:"none"});

			 }else {
				$("#JQ_export_btn_01").css({display:""});
				$("#JQ_delete_01").css({display:""});
			}

		})



	paramHandler();
	createPageHtml(10,1,0);



	var isOpenDefault=true;
	$("div[select]").each(function(){
		if($(this).attr("select").length >0)
		{
			isOpenDefault=false;
		}
	});

	/*
	if(isOpenDefault)
	{
		//resultAjax(path+"/comm/newtask.json","",parseNewTask,"JSON");
	}
	bindBall();
	*/
});





function parseNewTask(data){
	if(data.result != undefined)
	{
		data=data.result;
		if(data.taskList == undefined)
		{
			return ;
		}
		$("div.dropdown-list[data-name='taskId']").attr("select",data.ID);
		$("div.dropdown-list[data-name='lineId']").attr("select",data.LINEID);
		for(var i = 0;i<data.taskList.length;i++)
		{
			$(".selectTask").append('<li><a href="javascript:void(0);" id="'+data.taskList[i].ID+'">'+data.taskList[i].NAME+'</a></li>');
			$(".selectTask li:last").data("item",data.taskList[i]);
		}
		$(".selectTask").data("list",data.taskList);

		getSendBall(data.LINEID,data.BEGINMILEAGE,data.ENDMILEAGE);
		paramHandler();
		submitForm(1,10);

	}
}





/**
 * 处理进入页面是，预定义选项
 */
function paramHandler(){
	$("div.dropdown-list[data-name]").each(function(){
		var select=$(this).attr("select");
		if(select == "" ){
			return;
		}
		var obj=$(this);
		$(this).find("li a").each(function(){
			if($(this).attr("id")==select){
				obj.find(".checked a").attr("id",select);
				obj.find(".checked a").text($(this).text());
			}
		});
	});
}

/**
 * 导出excel
 */
function exportExl(fileName){
	var lineId=false;
	var taskSegmentId=false;
	var taskId=false;

	if($("div.dropdown-list[data-name='segmentId']").find(".drop-list-min a").attr("id") != undefined ){
		enlist=1;
	}else{
		enlist=0;
	}

	var param=[];


	param.push({name:"fileName",value:fileName});

	var  form='<form id="exportExl"  target="_blank" action="'+$("div.html-header").attr("data-exporturl")+'" >';
	//单选框
	$(".ck1[data-name] span.check-box .active").each(function(){
		param.push({name:$(this).parent().parent().attr("data-name"),value:$(this).parent().parent().attr("data")});
		//form+='<input type="hidden" name="'+$(this).parent().parent().attr("data-name")+'" value="'+$(this).parent().parent().attr("data")+'" />';
	});

	//复选框
	$(".ck span.check-box .active").each(function(){

		param.push({name:$(this).parent().attr("data-name"),value:$(this).parent().attr("data")});

		//form+='<input type="hidden" name="'+$(this).parent().attr("data-name")+'" value="'+$(this).parent().attr("data")+'" />';
//		data+="&"+$(this).attr("data-name")+"="+$(this).attr("data");

	});

	$("input[data-name]").each(function(){
		if( $(this).val().length > 0 )
		{
			param.push({name:$(this).attr("data-name"),value:$(this).val()});
			//form+='<input type="hidden" name="'+$(this).attr("data-name")+'" value="'+$(this).val()+'" />';
		}
	});

	$("div.dropdown-list[data-name]").each(function(){
		if($(this).find("a").attr("id") != "" && $(this).find("a").attr("id") != undefined)
		{
			param.push({name:$(this).attr("data-name"),value:$(this).find("a").attr("id")});
			//form+='<input type="hidden" name="'+$(this).attr("data-name")+'" value="'+$(this).find("a").attr("id")+'" />';
			if($(this).attr("data-name") == "lineId"){

				lineId=true;
			}else if($(this).attr("data-name") == "taskSegmentId"){

				taskSegmentId=true;
			}else if($(this).attr("data-name") == "taskId"){

				taskId=true;
			}
		}
	});
	var lineIdVal=window.line.val();
	var taskIdVal=window.task.val();
	var beginMileageVal=window.begin.val('mile');
	var endMileageVal=window.end.val('mile');

	if(lineIdVal != "")
	{
		lineId=true;
		param.push({name:"lineId",value:lineIdVal});
		param.push({name:"lineName",value:window.line.val('text')});
	}
	if(taskIdVal != "")
	{
		taskId=true;
		param.push({name:"taskId",value:taskIdVal});
		param.push({name:"taskName",value:window.task.val('text')});
	}
	if(beginMileageVal != "")
	{
		//taskId=true;
		param.push({name:"beginMileage",value:beginMileageVal});
		param.push({name:"beginName",value:window.begin.val('text')});
	}
	if(endMileageVal != "")
	{
		//taskId=true;
		param.push({name:"endMileage",value:endMileageVal});
		param.push({name:"endName",value:window.end.val('text')});
	}


	param.push({name:"enlist",value:enlist});
	param.push({name:"other",value:20});





	var obj = [window.line,window.task,window.begin,window.end];

	if(checkForm(obj)&&checkFormVerify($("#JQ_form")))
	{
		downFile($("div.html-header").attr("data-exporturl"),param);
	}

}




function exportApprarse(fileName){



	var lineId=false;
	var taskSegmentId=false;
	var taskId=false;

	if($("div.dropdown-list[data-name='segmentId']").find(".drop-list-min a").attr("id") != undefined ){
		enlist=1;
	}else{
		enlist=0;
	}

	var param=[];

	param.push({name:"fileName",value:fileName})

	var  form='<form id="exportExl"  target="_blank" action="'+$("div.html-header").attr("data-exporturl")+'" >';
	//单选框
	$(".ck1[data-name] span.check-box .active").each(function(){
		param.push({name:$(this).parent().parent().attr("data-name"),value:$(this).parent().parent().attr("data")})
	});

	//复选框
	$(".ck span.check-box .active").each(function(){

		param.push({name:$(this).parent().attr("data-name"),value:$(this).parent().attr("data")});

	});

	$("input[data-name]").each(function(){
		if( $(this).val().length > 0 )
		{
			param.push({name:$(this).attr("data-name"),value:$(this).val()});
		}
	});
	$("div.dropdown-list[data-name]").each(function(){
		if($(this).find("a").attr("id") != "" && $(this).find("a").attr("id") != undefined)
		{
			param.push({name:$(this).attr("data-name"),value:$(this).find("a").attr("id")});
			if($(this).attr("data-name") == "lineId"){

				lineId=true;
			}else if($(this).attr("data-name") == "taskSegmentId"){

				taskSegmentId=true;
			}else if($(this).attr("data-name") == "taskId"){

				taskId=true;
			}
		}
	});
	var lineIdVal=window.line.val();
	var taskIdVal=window.task.val();
	var beginMileageVal=window.begin.val('mile');
	var endMileageVal=window.end.val('mile');

	if(lineIdVal != "")
	{
		lineId=true;
		param.push({name:"lineId",value:lineIdVal});
	}
	if(taskIdVal != "")
	{
		taskId=true;
		param.push({name:"taskId",value:taskIdVal});
	}
	if(beginMileageVal != "")
	{
		param.push({name:"beginMileage",value:beginMileageVal});
	}
	if(endMileageVal != "")
	{
		param.push({name:"endMileage",value:endMileageVal});
	}

	param.push({name:"enlist",value:enlist});
	param.push({name:"other",value:20});

	param.push({name:"lineName",value:window.line.val('text')});
	param.push({name:"taskName",value:window.task.val('text')});
	param.push({name:"apprarse",value:"评价"});
	var obj = [window.line,window.task,window.begin,window.end];

	if(checkForm(obj)&&checkFormVerify($("#JQ_form")))
	{
		downFile($("div.html-header").attr("data-toApprarseurl"),param);
	}
}



/**
 * 开始搜索查询
 * @param pageNo 当前页码
 * @param pageSize 每页显示条数
 */
function submitForm(pageNo,pageSize){
	var lineId=false;
	var taskSegmentId=false;
	var taskId=false;

	if($("div.dropdown-list[data-name='segmentId']").find(".drop-list-min a").attr("id") != undefined ){
		enlist=1;
	}else{
		enlist=0;
	}


	var data="current="+pageNo+"&pageCount="+pageSize+"&enlist="+enlist+"&other=20";

	//单选框
	$(".ck1[data-name] span.check-box .active").each(function(){
		data+="&"+$(this).parent().parent().attr("data-name")+"="+$(this).parent().parent().attr("data");
	});
	//复选框
	$(".ck span.check-box .active").each(function(){

		data+="&"+$(this).parent().attr("data-name")+"="+$(this).parent().attr("data");

	});


	$("input[data-name]").each(function(){
		if( $(this).val().length > 0 )
		{
			data+="&"+$(this).attr("data-name")+"="+$(this).val();
		}
	});

	//下拉
	$("div.dropdown-list[data-name]").each(function(){
		if($(this).find(".drop-list-min a").attr("id") != "" && $(this).find(".drop-list-min a").attr("id") != undefined)
		{
			data+="&"+$(this).attr("data-name")+"="+$(this).find(".drop-list-min a").attr("id");

			if($(this).attr("data-name") == "lineId"){

				lineId=true;
			}else if($(this).attr("data-name") == "taskSegmentId"){

				taskSegmentId=true;
			}else if($(this).attr("data-name") == "taskId"){

				taskId=true;
			}
		}

	});

	var lineIdVal=window.line.val();
	var taskIdVal=window.task.val();
	var beginMileageVal=window.begin.val('mile');
	var endMileageVal=window.end.val('mile');

	if(lineIdVal != "")
	{
		lineId=true;
		data+="&lineId="+lineIdVal;
	}
	if(taskIdVal != "")
	{
		taskId=true;
		data+="&taskId="+taskIdVal;
	}
	if(beginMileageVal != "")
	{
		//taskId=true;
		data+="&beginMileage="+beginMileageVal;
	}
	if(endMileageVal != "")
	{
		data+="&endMileage="+endMileageVal;
	}
	var obj = [window.line,window.task,window.begin,window.end];

	if(checkForm(obj)&&checkFormVerify($("#JQ_form")))
	{
		resultAjax($("div.html-header").attr("data-searchurl"),data,setPageHtml,"JSON");
	}
	

}


